using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class LoaiLyDoPhatRepository
	{
		public static List<LoaiLyDoPhat> SelectAll()
		{
			return DataContext.Instance.LoaiLyDoPhat.ToList();
		}

		public static LoaiLyDoPhat SelectByID(int idloailydophat)
		{
			return DataContext.Instance.LoaiLyDoPhat.FirstOrDefault(item => item.IDLoaiLyDoPhat == idloailydophat );
		}

		public static bool Insert(LoaiLyDoPhat obj)
		{
			try
			{
				DataContext.Instance.LoaiLyDoPhat.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int idloailydophat)
		{
			try
			{
				var delitem = DataContext.Instance.LoaiLyDoPhat.FirstOrDefault(item => item.IDLoaiLyDoPhat == idloailydophat );
				DataContext.Instance.LoaiLyDoPhat.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<LoaiLyDoPhat> RetrieveByID(int idloailydophat)
		{
			return (from item in DataContext.Instance.LoaiLyDoPhat where  item.IDLoaiLyDoPhat == idloailydophat  select item).ToList();
		}

	}
}